home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / bccapp.zip / STATS.C < prev    next >
C/C++ Source or Header  |  1991-05-07  |  9KB  |  319 lines

  1. /*
  2.  *
  3.  *    Baseball statistic manager
  4.  *
  5.  * (C) 1990 Vision Software
  6.  *
  7.  * $Id: main.c 1.6 91/03/22 16:09:37 pcalvin beta Locker: pcalvin $
  8.  *
  9.  */
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #include <stdhdr.h>
  15.  
  16. #include <adl.h>
  17. #include <menu.h>
  18. #include <edit.h>
  19. #include <batch.h>
  20. #include <report.h>
  21.  
  22. #include "stats.h"
  23.  
  24. /*
  25.  *    Macro to extract size and base from an array.  In our library,
  26.  *    array parameters are always passed in the count,base sequence.  This
  27.  *    macro creates that for use.  May ONLY be used on locally defined
  28.  * arrays.
  29.  */
  30. #define CAndPFromRg(rg) (sizeof(rg)/sizeof(rg[0])),rg
  31.  
  32. /*
  33.  * This static member of DATABASE controls where the class
  34.  * looks for files.
  35.  */
  36. SZ ACCESS::szDataPath = "data\\";
  37.  
  38. /*
  39.  *    Each menu is any array of ENTs.  A pulldown is created by an 
  40.  *    array of BARs..
  41.  */
  42. STATIC ENT pentHitters[] = {
  43.    { "Add/Edit/Delete Hitters",0,CreateHitters,"Edit/Create or Delete Hitters" },
  44.     { "Batting Champs",0,BattingChamps,"Report on Batting Champions" },
  45.     { "Home Run Champs",0,HomeRunChamps,"Report on Home Run Champions" },
  46.     { "Stolen Base Champs",0,StolenBaseChamps,"Report on Stolen Base Champions" }
  47.     };
  48.     
  49. STATIC ENT pentPitchers[] = {
  50.    { "Add/Edit/Delete Pitchers",0,CreatePitchers,"Edit/Create or Delete Pitchers" },
  51.     { "ERA Leaders",0,ERAChamps,"Report on Earned Run Average Leaders" },
  52.     { "Win Leaders",0,WinChamps,"Report on Win Leaders" },
  53.     { "Save Leaders",0,SaveChamps,"Report on Save Leaders" },
  54.     { "Strikeout Leaders",1,StrikeoutChamps,"Report on Strikeout Leaders" }
  55.    };
  56.  
  57. STATIC BAR menu[] = {
  58.    { "System",0,4,pentVision },
  59.    { "Hitters",0,CAndPFromRg(pentHitters) },
  60.    { "Pitchers",0,CAndPFromRg(pentPitchers) }
  61.    };
  62.  
  63. /*
  64.  *    Create Hitters Database/Index files
  65.  */
  66. HITTERS htrs;
  67. DATABASE dtbHitters(&htrs,sizeof(htrs),"hitter",fTrue);
  68. CID cidAverage = dtbHitters.CidIndexOn("average",htrs.rgchAverage,4);
  69. CID cidHomeRun = dtbHitters.CidIndexOn("hr",htrs.rgchHomeRuns,3);
  70. CID cidStolen = dtbHitters.CidIndexOn("sb",htrs.rgchStolen,2);
  71. CID cidHitter = dtbHitters.CidIndexOn("hplay",htrs.rgchName,15);
  72. CID cidHits = dtbHitters.CidIndexOn("hits",htrs.rgchHits,3);
  73.  
  74. /*
  75.  *    Create Pitchers Database/Index files
  76.  */
  77. PITCHERS pchrs;
  78. DATABASE dtbPitcher(&pchrs,sizeof(pchrs),"pitcher",fTrue);
  79. CID cidPitcher = dtbPitcher.CidIndexOn("pplay",pchrs.rgchName,15);
  80. CID cidERA = dtbPitcher.CidIndexOn("era",pchrs.rgchERA,5);
  81. CID cidWins = dtbPitcher.CidIndexOn("wins",pchrs.rgchWins,2);
  82. CID cidSaves = dtbPitcher.CidIndexOn("saves",pchrs.rgchSaves,3);
  83. CID cidSO = dtbPitcher.CidIndexOn("so",pchrs.rgchSO,3);    
  84.  
  85. /*
  86.  *    Main loop.  Because this is a simple menu driven program, we do 
  87.  *    VERY little here..
  88.  */
  89. int main()
  90.    {
  91.    PULLDOWN pull(1,CAndPFromRg(menu));
  92.  
  93.    pull.ShowBar();
  94.    
  95.    while (fTrue)
  96.       {
  97.       if (pull.CdGet() == cdEscape && FAskSz("Exit System?"))
  98.          break;
  99.       }
  100.  
  101.    exit(0);
  102.    }
  103.  
  104.  
  105. /*
  106.  *    By using the BATCH class, we may randomly edit the statistics of
  107.  * of any hitter very easily.
  108.  */
  109. EXTERN VOID CreateHitters()
  110.     {
  111.     HELP help("");
  112.     BATCH bth(dtbHitters,"Edit/Create or Delete Hitters");
  113.     
  114.     STATIC ENT pent[] = {
  115.         { "Name",0,0,"Sort edit by hitters' name" },
  116.         { "Average",0,0,"Sort edit by hitters' average" },
  117.         { "Hits",0,0,"Sort edit by number of hits" },
  118.         { "Home Runs",0,0,"Sort edit by number of home runs" },
  119.         { "Stolen Bases",0,0,"Sort edit by number of stolen bases" }
  120.        };
  121.  
  122.    bth.IndexSelector(1,1,"Sorted By :",CAndPFromRg(pent));
  123.  
  124.     bth.Index(2,1,cidHitter,"Player  :",'U'); 
  125.     bth.Field(2,29,"Team :",htrs.rgchTeam,'U',3);
  126.     bth.Index(4,5,cidAverage,"Average :",'X');
  127.     
  128.     bth.Field(4,23,"Games :",htrs.rgchGames,'9',3);
  129.     bth.Field(6,5,"At Bats :",htrs.rgchAtBat,'9',3);
  130.     bth.Field(6,23,"Runs  :",htrs.rgchRuns,'9',3);
  131.     bth.Index(7,5,cidHits,"Hits    :",'9');
  132.     bth.Index(7,23,cidHomeRun,"HR    :",'9');
  133.     bth.Field(8,5,"Doubles :",htrs.rgchDoubles,'9',3);
  134.     bth.Field(8,23,"RBIs  :",htrs.rgchRBI,'9',3);
  135.     bth.Field(9,5,"Triples :",htrs.rgchTriples,'9',3);
  136.     bth.Field(9,23,"Walks :",htrs.rgchWalks,'9',3);
  137.     bth.Field(10,5,"Bases   :",htrs.rgchTotal,'9',3);
  138.     bth.Field(10,23,"SO    :",htrs.rgchSO,'9',3);
  139.     bth.Index(12,1,cidStolen,"Steals :",'9');
  140.     bth.Field(12,15,"Caught :",htrs.rgchCaught,'9',2);
  141.     bth.Field(12,29,"Errors :",htrs.rgchErrors,'9',2);
  142.  
  143.     bth.Read();
  144.     }
  145.     
  146. /*
  147.  * Editing another structure is just as easy...
  148.  */
  149. EXTERN VOID CreatePitchers()
  150.     {
  151.     HELP help("");
  152.     BATCH bth(dtbPitcher,"Add/Edit/Delete Pitchers");
  153.     
  154.     STATIC ENT pent[] = {
  155.         { "Name",0,0,"Sort edit by pitchers' name" },
  156.         { "ERA",0,0,"Sort edit by pitchers ERA" },
  157.         { "Wins",0,0,"Sort edit by number of wins" },
  158.         { "Saves",0,0,"Sort edit by number of saves" },
  159.         { "Strike Outs",0,0,"Sort edit by number of strike outs" }
  160.        };
  161.  
  162.    bth.IndexSelector(1,1,"Sorted By :",CAndPFromRg(pent));
  163.  
  164.     bth.Index(2,1,cidPitcher,"Player  :",'U'); 
  165.     bth.Field(2,29,"Team :",pchrs.rgchTeam,'U',3);
  166.     bth.Index(4,2,cidERA,"ERA :",'X');
  167.     
  168.     bth.Index(4,16,cidWins,"Wins :",'9');
  169.     bth.Field(4,28,"Loses :",pchrs.rgchLoses,'9',2);
  170.     bth.Field(6,2,"Games    :",pchrs.rgchGames,'9',3);
  171.     bth.Field(6,20,"Hits        :",pchrs.rgchHits,'9',3);
  172.     bth.Field(7,2,"Complete :",pchrs.rgchComplete,'9',3);
  173.     bth.Field(7,20,"Runs        :",pchrs.rgchRuns,'9',3);
  174.     bth.Field(8,2,"Shutouts :",pchrs.rgchShutouts,'9',3);
  175.     bth.Field(8,20,"Earned Runs :",pchrs.rgchEarned,'9',3);
  176.     bth.Index(9,2,cidSaves,"Saves    :",'9');
  177.     bth.Field(9,20,"Home Runs   :",pchrs.rgchHomeRuns,'9',3);
  178.     bth.Field(10,2,"Innings  :",pchrs.rgchInnings,'9',3);
  179.     bth.Index(10,20,cidSO,"SO          :",'9');
  180.     bth.Field(11,20,"Walks       :",pchrs.rgchWalks,'9',3);
  181.  
  182.     bth.Read();
  183.     }
  184.  
  185. /*
  186.  *    Reports are created by selecting fields to display and (if desired) 
  187.  *    providing a filter for the database..
  188.  *
  189.  *    After that, everything is taken care of by the library..
  190.  */
  191. EXTERN VOID HittersReport(DATABASE &rdtb,HITTERS &rhtrs,BOOL (*pfnFValid)(DBASE *pdb),BOOL fForward)
  192.     {
  193.     REPORT rpt(rdtb);
  194.  
  195.     rpt.SetFilterTo(pfnFValid);
  196.  
  197.     rpt.Entry(1,rhtrs.rgchName,15,"Name");
  198.     rpt.Entry(17,rhtrs.rgchTeam,3,"For");
  199.     rpt.Entry(21,rhtrs.rgchAverage,4," Avg");
  200.     rpt.Entry(26,rhtrs.rgchGames,3," G");
  201.     rpt.Entry(30,rhtrs.rgchAtBat,3," AB");
  202.     rpt.Entry(34,rhtrs.rgchRuns,3," R");
  203.     rpt.Entry(38,rhtrs.rgchHits,3," H");
  204.     rpt.Entry(42,rhtrs.rgchDoubles,3," D");
  205.     rpt.Entry(46,rhtrs.rgchTriples,3," T");
  206.     rpt.Entry(50,rhtrs.rgchHomeRuns,3," HR");
  207.     rpt.Entry(54,rhtrs.rgchRBI,3,"RBI");
  208.     rpt.Entry(58,rhtrs.rgchWalks,3," W");
  209.     rpt.Entry(62,rhtrs.rgchSO,3," SO");
  210.     rpt.Entry(66,rhtrs.rgchStolen,2,"SB");
  211.  
  212.     rpt.Generate(fForward,FAskSz("Would you like to send report to the Printer?"));
  213.     }
  214.  
  215. /*
  216.  *    Again, C++ allows us to simply create reports as desired..
  217.  */
  218. EXTERN VOID PitchersReport(DATABASE &rdtb,PITCHERS &rpchrs,BOOL (*pfnFValid)(DBASE *pdb),BOOL fForward)
  219.     {
  220.     REPORT rpt(rdtb);
  221.     
  222.     rpt.SetFilterTo(pfnFValid);
  223.     rpt.Entry(1,rpchrs.rgchName,15,"Name");
  224.     rpt.Entry(17,rpchrs.rgchTeam,3,"For");
  225.     rpt.Entry(21,rpchrs.rgchWins,2," W");
  226.     rpt.Entry(24,rpchrs.rgchLoses,2," L");
  227.     rpt.Entry(27,rpchrs.rgchERA,5," ERA");
  228.     rpt.Entry(33,rpchrs.rgchGames,3," G");
  229.     rpt.Entry(37,rpchrs.rgchShutouts,3," SO");
  230.     rpt.Entry(41,rpchrs.rgchSaves,3," SV");
  231.     rpt.Entry(45,rpchrs.rgchInnings,5," INN");
  232.     rpt.Entry(51,rpchrs.rgchHits,3," H");
  233.     rpt.Entry(55,rpchrs.rgchRuns,3," R");
  234.     rpt.Entry(59,rpchrs.rgchEarned,3," ER");
  235.     rpt.Entry(63,rpchrs.rgchHomeRuns,3," HR");
  236.     rpt.Entry(67,rpchrs.rgchWalks,3," BB");
  237.     rpt.Entry(71,rpchrs.rgchSO,3," K");
  238.  
  239.     rpt.Generate(fForward,FAskSz("Would you like to send report to the Printer?"));
  240.     };
  241.     
  242. /*
  243.  *    Filter functions used by REPORT.  In these cases, we make sure that
  244.  *    the pitcher/batter have worked in enough games to be valid for
  245.  *    the report.
  246.  */
  247. EXTERN BOOL FValidPitcher(DBASE *pdb)
  248.     {
  249.      PITCHERS *ppchrs = (PITCHERS *)pdb;
  250.  
  251.      if (atoi(ppchrs->rgchInnings) < 70)
  252.          return (fFalse);
  253.     else 
  254.         return (fTrue);
  255.     }
  256.  
  257. EXTERN BOOL FValidBatter(DBASE *pdb)
  258.     {
  259.      HITTERS *phtrs = (HITTERS *)pdb;
  260.  
  261.      if (atoi(phtrs->rgchAtBat) < 370)
  262.          return (fFalse);
  263.     else 
  264.         return (fTrue);
  265.     }
  266.  
  267. /* 
  268.  *    All remaining funtions simply Select the appropriate index, and
  269.  *    execute the report.
  270.  */
  271. EXTERN VOID ERAChamps()
  272.     {
  273.     Verify(dtbPitcher.FIndexTo(cidERA));
  274.     
  275.     PitchersReport(dtbPitcher,pchrs,FValidPitcher,fTrue);
  276.     }
  277.     
  278. EXTERN VOID WinChamps()
  279.     {
  280.     Verify(dtbPitcher.FIndexTo(cidWins));
  281.  
  282.     PitchersReport(dtbPitcher,pchrs,Nil);
  283.     }
  284.     
  285. EXTERN VOID SaveChamps()
  286.     {
  287.     Verify(dtbPitcher.FIndexTo(cidSaves));
  288.     
  289.     PitchersReport(dtbPitcher,pchrs,Nil);
  290.     }
  291.     
  292. EXTERN VOID StrikeoutChamps()
  293.     {
  294.     Verify(dtbPitcher.FIndexTo(cidSO));
  295.  
  296.     PitchersReport(dtbPitcher,pchrs,Nil);
  297.     }
  298.     
  299. EXTERN VOID BattingChamps()
  300.     {
  301.     Verify(dtbHitters.FIndexTo(cidAverage));
  302.  
  303.     HittersReport(dtbHitters,htrs,FValidBatter);
  304.     }
  305.     
  306. EXTERN VOID HomeRunChamps()
  307.     {
  308.     Verify(dtbHitters.FIndexTo(cidHomeRun));
  309.  
  310.     HittersReport(dtbHitters,htrs,Nil);
  311.     }
  312.     
  313. EXTERN VOID StolenBaseChamps()
  314.     {
  315.     Verify(dtbHitters.FIndexTo(cidStolen));
  316.  
  317.     HittersReport(dtbHitters,htrs,Nil);
  318.     }
  319.